#include "RotationControllerNode.h"
#include "RotationController.h"
#include "TRSTransform.h"

RotationControllerNode::RotationControllerNode(tstring name):AnimationNode(name),m_pController(new RotationController())
{
}


RotationControllerNode::~RotationControllerNode(void)
{
	if( m_pController!= NULL) delete m_pController;
}

void RotationControllerNode::SetRotationController(RotationController* pController)
{
	if ( m_pController != NULL ){
		delete m_pController;
		m_pController = pController;
	}
}

const bool RotationControllerNode::GetTransformAt(float time, DAEMatrix& deltaTrans, DAEMatrix& matrix)
{
	if ( m_pController != NULL ){
		DAEFloat3& rotation = m_pController->GetRotation(time);
		TRSTransform trs;
		trs.SetRotation(rotation.x,rotation.y,rotation.z);
		trs.SetTranslation(m_Translation.x,m_Translation.y,m_Translation.z);
		trs.SetScale(m_Scale.x,m_Scale.y,m_Scale.z);
		if ( m_pController->GetRotationSpace() == RotationController::WORLD )
		{
			DAEMatrix anim = trs.GetCompiledMatrix();
			matrix.SetValues(anim);
			return true;
		}else{
			DAEMatrix anim = trs.GetCompiledMatrix();
			anim.Multiply(&matrix,&deltaTrans);
			return true;
		}
	}else
		return false;
}
